package cn.dimao.dhd.controller;

import cn.dimao.dhd.pojo.UserTb;
import cn.dimao.dhd.pojo.vo.CommonResult;
import cn.dimao.dhd.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 15543
 * @version 1.0
 * @project text
 * @description 用户表接口
 * @date 2024/6/1 17:08:51
 */
@RequestMapping("user")
@RestController
public class UserController {

    @Resource
    UserService userService;

    /**
     * 根据id查询userTb记录
     * @param id user id
     * @return userTb对象
     */
    @GetMapping("/selectUserTbById")
    public CommonResult selectUserTbById(@RequestParam Integer id){
        return userService.selectUserTbById(id);
    }


    //todo 1:修改手机号密码登陆接口，登陆成功返回Token，推荐使用数据结构map
    //todo 2:写一个根据token获取用户信息的接口，返回userTb对象(password)要混淆。例如：xxxxxxx
    /**
     *
     * @param phone
     * @param password
     * @return
     */
    @GetMapping("/loginByPhone")
    public CommonResult loginByPhone(@RequestParam String phone,@RequestParam String password){
        return userService.loginByPhone(phone,password);
    }

    /**
     * 根据id删除
     * @param id user id
     * @return 是否删除成功的信息
     */
    @DeleteMapping("/deleteUserTbById")
    public CommonResult deleteUserTbById(@RequestParam Integer id){
        return userService.deleteUserTbById(id);
    }


    /**
     * 添加userTb
     * @param  userTb user userTb
     * @return userTb对象
     */
    @PostMapping("/saveUserTb")
    public CommonResult saveUserTb(@RequestBody UserTb userTb){
        return userService.saveUserTb(userTb);
    }

    /**
     * 修改userTb
     * @param  userTb user userTb
     * @return userTb对象
     */
    @PutMapping("/updateUserTb")
    public CommonResult updateUserTb(@RequestBody UserTb userTb){
        return userService.updateUserTb(userTb);
    }
}